package com.assess.service.impl;

import com.assess.entity.AssessIndicatorWeight;
import com.assess.mapper.AssessIndicatorWeightMapper;
import com.assess.service.AssessIndicatorWeightService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AssessIndicatorWeightServiceImpl extends ServiceImpl<AssessIndicatorWeightMapper, AssessIndicatorWeight> implements AssessIndicatorWeightService {
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveBatchWeights(List<AssessIndicatorWeight> weights) {
        if (weights == null || weights.isEmpty()) return;
        Long parentId = weights.get(0).getParentId();
        Integer version = weights.get(0).getVersion();
        Long schemeId = weights.get(0).getSchemeId();
        // 覆盖策略：删除同 parentId/version/(schemeId) 后写入
        this.remove(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<AssessIndicatorWeight>()
                .eq(AssessIndicatorWeight::getParentId, parentId)
                .eq(AssessIndicatorWeight::getVersion, version)
                .eq(schemeId != null, AssessIndicatorWeight::getSchemeId, schemeId));
        this.saveBatch(weights);
    }
}


